<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>创建项目</title>
    {% load static %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>

    <link type="text/css" rel="stylesheet" href="/static/css/metroStyle.css">
    <link type="text/css" rel="stylesheet" href="/static/css/treeSelectStyle.css">
    <script src="/static/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="/static/js/treeSelect.2.0.js"></script>
    <script type="text/javascript" src="/static/js/xm-select.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space10">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">项目名称<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="pro_name" placeholder="请输入项目名称" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
            </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">约定书<span style="color: red">*</span></label>
                <div class="layui-input-block" id="pro_contract">

                </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">项目负责人<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="paper_manager" id="paper_manager" placeholder="项目负责人" autocomplete="off" disabled class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">被审计单位<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="audit_obj" id="audit_obj" placeholder="被审计单位名称" autocomplete="off" disabled class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">签字人1<span style="color: red">*</span></label>
            <div class="layui-input-block" name="sign_one" id="sign_one">

            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">签字人2<span style="color: red">*</span></label>
            <div class="layui-input-block" id="sign_two" name="sign_two">

                </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">文号</label>
            <div class="layui-input-block">

                <input type="text" name="pro_number" style="width: 90%;" placeholder="该项自动生成" autocomplete="off" disabled class="layui-input">
                <button type="button" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-primary" style="margin-left: 90%;margin-top: -55px;">
                    <i class="layui-icon layui-icon-down"></i>
                </button>

            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">打印份数<span style="color: red">*</span></label>
            <div class="layui-input-block">
                    <input type="text" name="print_number" placeholder="输入打印份数" autocomplete="off" class="layui-input"
                       lay-verify="required">
                </div>
        </div>
        </div>
        <div class="layui-form-item layui-form-text" style="padding-top: 10px;">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" placeholder="请输入备注内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script>
    layui.use(["okUtils", "form", "tree", "okLayer"], function () {
        let $ = layui.$;
        let form = layui.form;
        let okUtils = layui.okUtils;
        let okLayer = layui.okLayer;
        let tree = layui.tree;
        let util = layui.util;
        okLoading.close();
        // 这里得把switch的状态弄对，不然，如果他创建就停用，数据就传不过去了
        form.on("submit(add)", function (data) {
            console.log(data.field)
            okUtils.ajax("{% url 'project:project_insert' %}", "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });

//-------------------------------------------------------------------------------

        var demo1 = xmSelect.render({
            el: '#pro_contract',
            name:'pro_contract',
            radio: true,
            clickClose: true,
            filterable: true,
            paging: true,
            pageSize: 3,
            layVerType: 'msg',
            toolbar: {show: true},
            layVerify: 'required',
            prop: {
                name: 'paper_code',
                value: 'id',
            },
            data: [],
            on: function (data) {
                var arr = data.arr;
                if (arr.length === 0) {
                    $('#paper_manager').val('');
                    $('#audit_obj').val('');
                } else {
                    $('#audit_obj').val(arr[0].audit_obj);
                    $('#paper_manager').val(arr[0].paper_manager);
                }
            }

        });
        $.ajax({
            url: "{% url 'business:confiles_contracts' %}",
            type: "GET",
            success: function (ret) {
                var node = ret;
                demo1.update({
                    data: node.data,
                })

            },
            error: function () {
            }
        });
        //--------------------------]
        var node = null;
        var demo2 = xmSelect.render({
            el: '#sign_one',
            name: 'sign_one',
            radio: true,
            clickClose: true,
            filterable: true,
            paging: true,
            pageSize: 3,
            layVerType: 'msg',
            toolbar: {show: true},
            layVerify: 'required',
            on: function (data) {
                var change = data.change;
                if (change[0].id == demo3.getValue('value')) {
                    okLayer.redCryMsg('不允许为同一签字人！', function () {
                        demo2.warning('#FF5722', true);
                        demo2.setValue([ ])
                    })
                }
            },
            prop: {
                name: 'user_name',
                value: 'id',
            },
            height: 'auto',
            data: []
        });
        $.ajax({
            url: "{% url 'users:users_sign' %}",
            type: "GET",
            success: function (ret) {
                var node = ret;
                demo2.update({
                    data: node.data,
                    autoRow: true,
                });
                demo3.update({
                    data: node.data,
                    autoRow: true,
                })
            },
            error: function () {
            }
        });
        var demo3 = xmSelect.render({
            el: '#sign_two',
            name: 'sign_two',
            radio: true,
            clickClose: true,
            filterable: true,
            paging: true,
            pageSize: 3,
            layVerType: 'msg',
            toolbar: {show: true},
            layVerify: 'required',
            on: function (data) {
                var change = data.change;
                if (change[0].id == demo2.getValue('value')) {
                    okLayer.redCryMsg('不允许为同一签字人！', function () {
                        demo3.warning('#FF5722', true);
                        demo3.setValue([ ])
                    })
                }
            },
            prop: {
                name: 'user_name',
                value: 'id',
            },
            height: 'auto',
            data: []
        });
    });
</script>
</body>
</html>
